﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Store.WP7.ViewModels
{
    public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected void RaisePropertyChanged<T>(Expression<Func<T>> expression)
        {
            if (!(expression.Body is MemberExpression))
                return;

            MemberExpression memberExpression = (MemberExpression)expression.Body;
            string propertyName = memberExpression.Member.Name;
            RaisePropertyChanged(propertyName);
        }
    }
}
